package com.jnsw.testkotlin.updateapp;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.allenliu.versionchecklib.AVersionService;
import com.allenliu.versionchecklib.VersionDialogActivity;
import com.allenliu.versionchecklib.VersionParams;
import com.jnsw.testkotlin.R;

public class VdialogActivity extends VersionDialogActivity {

    private String  title;
    private String  msg;
    private String  downloadUrl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        //版本更新获取到参数后 调用此页面打开提示框
       Boolean isUseDefault = getIntent().getBooleanExtra("isUseDefault", false);
        if (isUseDefault) {
            title = getIntent().getStringExtra("title");
            msg = getIntent().getStringExtra("text");
            VersionParams versionParams = getIntent().getParcelableExtra(AVersionService.VERSION_PARAMS_KEY);
            downloadUrl = getIntent().getStringExtra("downloadUrl");
            if (title != null && msg != null && downloadUrl != null && versionParams != null){
            }
        }
        //onctreate之后调用showVersionDialog 方法  需在create之前获取参数
        super.onCreate(savedInstanceState);

//        setContentView(R.layout.activity_vdialog);
    }




    /**
     * 自定义更新展示界面 直接重写此方法就好
     */
    @Override
    public void showVersionDialog() {
        //使用默认的提示框直接调用父类的方法,如果需要自定义的对话框，那么直接重写此方法
        // super.showVersionDialog();
//            super.showVersionDialog();


        final BaseDialog baseDialog = new BaseDialog(this, R.style.BaseDialog, R.layout.activity_vdialog);


        TextView tv_title = (TextView) baseDialog.findViewById(R.id.title);
        TextView tv_msg = (TextView) baseDialog.findViewById(R.id.msg);
        tv_title.setText(title);
        tv_msg.setText(msg);

        TextView tvCancel = (TextView) baseDialog.findViewById(R.id.tv_cancel);
        TextView tvUpdate = (TextView) baseDialog.findViewById(R.id.tv_update);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                onCancelClick();
                baseDialog.dismiss();
                finish();
//                VdialogActivity.this.finish();
                Toast.makeText(getApplicationContext(),"quxiao",Toast.LENGTH_SHORT).show();
            }
        });
        tvUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                baseDialog.dismiss();
                downloadFile("http://www.apk3.com/uploads/soft/guiguangbao/UCllq.apk");
            }
        });
        baseDialog.show();
    }



}
